<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <style>
        .renyaun{
                position: absolute;
                 left: 0px;
                 top: 26px;
                 z-index: 3;
                 white-space: nowrap;
        }
        .renyuan span.ren {
            border-radius: 6px;
            background: #d0e0e0;
            cursor: pointer;
        }

        body {
            font-size: 13px
        }

        .row {
            border: 1px solid #ccc;
            margin: 0 auto;
        }

        .select1 {
            width: 140px;
            height: 26px;
            padding: 2px
        }

        .trBackgroundColor {
            background: #c5e1fe
        }

        .col6pd1 {
            padding: 10px 0;
        }

        .bqName {
            padding: 2px 4px;
            border-radius: 6px;
            background: #d0e0e0;
            cursor: pointer;
        }
    </style>
</head>

<body class="white-bg" style="color:#333;padding:0px;overflow-x:auto;">
<form action=""  id="add" method="post">
    <div class="container" style="width: 100%;overflow-x: auto;padding: 0">
         <div class="page-heade">
       <h2 class="title_color text-center">系统基本信息</h2>
    </div>
        <div class="ibox-content form-horizontal">



                <div class="form-group row" style="border:0">
                    <label for="systemName" class="col-xs-2 control-label">系统名称<span class="colorRed">*</span>:</label>
                    <div class="col-xs-2">
                        <input type="text" class="form-control" id="systemName" name="title" value="{$data.title}">

                    </div>
                    <div class="col-xs-8">
                        <i class="colorRed" style="font-style: normal;">不允许英文状态下输入的单引号</i>
                    </div>

                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group row" style="border:0">
                    <label for="systemName"class="col-xs-2 control-label">系统编号:</label>
                    <div class="col-xs-2">
                        <span>{$data.sn}</span>
                    </div>
                    <div class="col-xs-8">
                        <i class="colorRed" style="font-style: normal;">(温馨说明：如不填写系统编号，系统将自动分配一个编号。)</i>
                    </div>

                </div>
                <div class="hr-line-dashed" ></div>
                <div class="form-group row" style="border:0">
                    <label for="" class="col-xs-2 control-label">业务人员<span class="colorRed">*</span>:</label>
                    <div class="col-xs-2">
                        <div class="input-group">
                            <input name="AllCompany" id="testNoBtn" type="text" placeholder="请输入关键字或空格查询"
                                   class="input12 form-control" value="">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                            <div class="renyuan" id="renyuan">
                                {volist name="data.stuff" id="row"}
                                <span class="ren" data-id="{$row.id}">{$row.em_name}<span class="close"></span></span>
                                {/volist}
                            </div>
                        </div>

                    </div>
                    <div class="col-xs-8">
                        <a href="javascript:;" id="select">选择全公司</a>
                        <i class="colorRed" style="font-style: normal;">系统上级经销商的业务人员如果没有人，则系统业务人员必须填写</i>
                    </div>


                </div>

                <div class="hr-line-dashed" ></div>
                <div class="form-group row" style="border:0">
                    <label for="cusType" class="col-xs-2 control-label">客户类型<span class="colorRed">*</span>:</label>
                    <div class="col-xs-2">
                        <select name="cusType" id="cusType" class="form-control" name="cusType">
                            <option value="">请选择</option>
                            {volist name="customer_type" id="row"}
                            <option value="{$row.id}" {if $data.cusType==$row.id}selected{/if}>{$row.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group row" style="border:0">
                    <label for="oneCType" class="col-xs-2 control-label">一级渠道类型<span class="colorRed">*</span></label>
                    <div class="col-xs-2">
                        <select name="oneCType" id="oneCType" class="form-control">
                            <option value="">请选择</option>
                            {volist name="channel_type1" id="row"}
                            <option value="{$row.id}" {if $data.oneCType==$row.id}selected{/if}>{$row.title}</option>
                            {/volist}
                        </select>
                    </div>
                    <label for="twoCType"class="col-xs-2 control-label">二级渠道类型<span class="colorRed">*</span></label>
                    <div class="col-xs-2">
                        <select name="twoCType" id="twoCType" class="form-control">
                            <option value="">请选择</option>
                            {volist name="channel_type2" id="row"}
                            <option value="{$row.id}" {if $data.twoCType==$row.id}selected{/if}>{$row.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>

                <div class="form-group row" style="border:0">
                    <label for="detailAddress" class="col-xs-2 control-label">详细地址<span class="colorRed">*</span>:</label>
                    <div class="col-xs-5">
                        <input type="text" class="c4_input12 form-control" name="detailAddress" id="detailAddress" value="{$data.detailAddress}">
                    </div>

                </div>

        </div>
        <div class="row white-bg">
            <div class="col-md-12 padding_lr" style="background: #d0e0e0;line-height: 40px;text-align:left;font-size:15px">
                系统所属经销商信息
                <button class="btn btn-primary addSystemToAngency" style="float: right;margin:3px 10px 0 0">添加</button>
            </div>
        </div>
        <table class="table table-bordered da_table white-bg" style="margin-bottom:0" id="suoshujxs">
            <tr>
                <th>序号</th>
                <th>所属经销商</th>
                <th>经销商编码</th>
                <th>分区经理</th>
                <th>省办经理</th>
                <th>城市经理</th>
                <th>备注</th>
                <th>操作</th>
            </tr>

            {volist name="data.jxss" id="row" key="k"}
            <tr>
                <td>{$k}</td>
                <td>{if $row.default==1}{$row.title}{else}<span class="bqName">{$row.title}<span class="delBqName">&times;</span></span><input type="hidden" class="form-control" name="jxs[id][]" value="{$row.jxs_id}">{/if}</td>
                <td><a href="javascript:;">{$row.sn}</a></td>
                <td><a href="javascript:;">{$row.zoning_head}</a></td>
                <td><a href="javascript:;">{$row.provice_head}</a></td>
                <td><a href="javascript:;">{$row.city_head}</a></td>
                <td>{if $row.default==1}{$row.brief}{else}<input type="text" class="form-control" name="jxs[brief][]" value="{$row.brief}">{/if}</td>
                <td>{if $row.default==1}默认所属经销商{else}<button class="btn btn-danger delThisTr">删除</button>{/if}</td>
            </tr>
            {/volist}

        </table>
        <div class="row border-bottom white-bg">
            <div class="col-md-12 padding_lr" style="background: #d0e0e0;line-height: 40px;text-align:left;font-size:15px">
                系统联络信息<span class="colorRed">(至少填写一条)</span>
            </div>
        </div>
        <table class="table table-bordered da_table1 white-bg" style="margin-bottom:0">
            <thead>
            <tr>
                <th><label for=""></label>联络人</th>
                <th>电话</th>
                <th>手机</th>
                <th>传真</th>
                <th>电子邮件</th>
                <th>职务</th>
                <th>邮寄地址</th>
                <th>邮编</th>
                <th>
                    <button class="btn btn-success addManInfo">添加</button>
                </td>
            </tr>
            </thead>
            <tbody>
            {volist name="data.ci" id="row"}
            <tr>
                <td>{$row.name}</td>
                <td>{$row.phone}</td>
                <td>{$row.mobile}</td>
                <td>{$row.fax}</td>
                <td>{$row.email}</td>
                <td>{$row.job}</td>
                <td>{$row.addr}</td>
                <td>{$row.zipcode}</td>
                <td>
                    <a href="javascript:;" class="btn btn-danger delthis2" data-id="{$row.id}">{if $row.isdel==1}启用{else}删除{/if}</a>
                </td>
            </tr>
            {/volist}
            </tbody>


        </table>
        <div class="row border-bottom white-bg border_S">
            <div class="col-sm-1" style="text-align: center;line-height: 50px">备注</div>
            <div class="col-sm-11">
                <div class="ibox float-e-margins" style="margin-bottom: 0">
                    <div class="ibox-content no-padding">

                        <div class="summernote">
                            {$data.brief}
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="row border-bottom">
            <div class="col-md-12 border_S padding_lr"
                 style="background: #d0e0e0;line-height: 40px;text-align:left;font-size:15px">系统管理日志
            </div>
        </div>
        <table class="table table-hover table-bordered da_table2 white-bg" style="margin-bottom:0">
            <tr>
                <th>时间</th>
                <th>姓名</th>
                <th>内容</th>
            </tr>
            {volist name="system_log" id="row"}
            <tr>
                <td>{:date('Y-m-d H:i',$row.ctime)}</td>
                <td>{$row.cuser}</td>
                <td>{$row.content}</td>
            </tr>
            {/volist}
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px">
            <ul class="list-group" style="margin-left:-20px;margin-right:-10px;">
                {volist name="data.attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.link}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
        <div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
            <input type="button" class="btn btn-success" style="margin-right: 15px" value="提交" id="tijiao">
            <input type="button" class="btn btn-warning" value="返回" onclick="back()">
        </div>
    </div>

</form>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<!-- <script src="js/plugins/layer/layer.min.js"></script> -->

<!-- 自定义js -->
<script src="__STATIC__/layout/js/plugins/summernote/summernote.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote-zh-CN.js"></script>

<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script>
    /*系统所属经销商信息添加删除*/
    $(".addSystemToAngency").click(function () {
        var len = $(".da_table tr").length;
        var str = ' <tr><td class="NoId">' + len + '</td><td>' +
            '<span class="changeThis">\n' +
            '                <div style="display: inline-block;vertical-align: -22px;margin-top: 10px;margin-bottom: 9px;">\n' +
            '                        <div class="input-group">\n' +
            '                            <input name="AllCompany" id="testNoBtn2" type="text" placeholder="请输入关键字或空格查询" class="testNoBtn2 input12 form-control" value="">\n' +
            '                            <div class="input-group-btn">\n' +
            '                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
            '                                    <span class="caret"></span>\n' +
            '                                </button>\n' +
            '                                <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
            '                                </ul>\n' +
            '                            </div>\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                <a href="javascript:;" class="changeThisA btn btn-outline btn-default select2">选择</a>\n' +
            '            </span><input type="hidden" name="jxs[id][]" value="">' +
            '</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td><input type="text" class="form-control" name="jxs[brief][]"></td><td><button class="btn btn-danger delThisTr">删除</button></td></tr>'
        $(".da_table tbody").append(str);
        var _o = $('.da_table tbody tr').last()
        _o.find(".testNoBtn2").bsSuggest({
            url: "{:url('jxsjson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias: {userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            var testNoBtn = $(this).closest('td')
            testNoBtn.html('<span class="bqName" data-id="'+keyword.id+'">'+keyword.key+'<span class="delBqName">×</span></span><input type="hidden" name="jxs[id][]" value="'+keyword.id+'">')
            //ajax查询经销的编码、分区经理、省办经理、城市经理，并赋值给邮编的td
            $.post('{:url("findJxs")}',{id:keyword.id},function (data) {
                testNoBtn.next('td').html(data.sn)
                testNoBtn.next('td').next('td').html(data.zoning)
                testNoBtn.next('td').next('td').next('td').html(data.provice)
                testNoBtn.next('td').next('td').next('td').next('td').html(data.city)
            },'json')
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
        return false
    })

    $(".da_table").on("click", ".delThisTr", function () {
        $(this).parent().parent().remove();
        var len = $(".da_table tr").length;
        var NoId = $('.NoId');
        for (var i = 0; i < len; i++) {
            $(NoId[i]).html(i + 1)
        }
        return false
    })

    //取消选择所属经销商
    $("body").on('click','.delBqName',function () {
        var _o = $(this).closest('td')
        var str = '<span class="changeThis">\n' +
            '                <div style="display: inline-block;vertical-align: -22px;margin-top: 10px;margin-bottom: 9px;">\n' +
            '                        <div class="input-group">\n' +
            '                            <input name="AllCompany" type="text" placeholder="请输入关键字或空格查询" class="testNoBtn2 input12 form-control" value="">\n' +
            '                            <div class="input-group-btn">\n' +
            '                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
            '                                    <span class="caret"></span>\n' +
            '                                </button>\n' +
            '                                <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
            '                                </ul>\n' +
            '                            </div>\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                <a href="javascript:;" class="changeThisA btn btn-outline btn-default select2">选择</a>\n' +
            '            </span>'
        $(this).parent().parent().html(str)

        _o.next('td').html('')
        _o.next('td').next('td').html('')
        _o.next('td').next('td').next('td').html('')
        _o.next('td').next('td').next('td').next('td').html('')

        _o.find(".testNoBtn2").bsSuggest({
            url: "{:url('jxsjson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias: {userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            var testNoBtn = $(this).closest('td')
            testNoBtn.html('<span class="bqName" data-id="'+keyword.id+'">'+keyword.key+'<span class="delBqName">×</span></span><input type="hidden" name="jxs[id][]" value="'+keyword.id+'">')
            //ajax查询经销的编码、分区经理、省办经理、城市经理，并赋值给邮编的td
            $.post('{:url("findJxs")}',{id:keyword.id},function (data) {
                testNoBtn.next('td').html(data.sn)
                testNoBtn.next('td').next('td').html(data.zoning)
                testNoBtn.next('td').next('td').next('td').html(data.provice)
                testNoBtn.next('td').next('td').next('td').next('td').html(data.city)
            },'json')
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
        return false
    })


    $(".changeThisA").click(function () {
        // 点击弹出框选择确定后
        var str = '<span class="bqName">安顺市佳和贸易有限公司<span class="delBqName">&times;</span></span>'
        return false
    })

    // 添加系统联系人信息
    $(".addManInfo").on("click", function () {
        var str = '<tr><td><input type="text" class="form-control input1" name="systemContact[name][]"></td><td><input type="text" class="form-control input2" style="width:20%;    display: inline-block;" name="systemContact[phone1][]">-<input type="text" class="form-control input22" style="width:70%;display: inline-block;" name="systemContact[phone2][]"></td><td><input type="text" class="form-control input21" name="systemContact[mobile][]"></td><td><input type="text" class="form-control input2" style="width:20%;display: inline-block;" name="systemContact[fax1][]">-<input type="text" class="form-control input22" style="width:70%;display: inline-block;" name="systemContact[fax2][]"></td><td><input type="text" class="form-control input21"  name="systemContact[email][]"></td><td><input type="text" class="form-control input21"  name="systemContact[job][]"></td><td><input type="text" class="form-control input21"  name="systemContact[addr][]"></td><td><input type="text" class="form-control input21"  name="systemContact[zipcode][]"></td><td><button class="btn btn-danger delthis">删除</button></td></tr>'
        $(this).parents(".da_table1").append(str);
        return false
    })

    $(document).on("click", ".delthis", function () {
        $(this).parent().parent().remove();
        return false
    })

</script>

<!--富文本编辑器-->
<script>
    $(document).ready(function () {

        $('.summernote').summernote({
            lang: 'zh-CN'
        });

    });

    function back() {
        window.history.go(-1)
    }
</script>

<!--提交等相关事件-->
<script>
    $(function () {
        //移除附件
        $('.removeIt').on('click',function(){
            var id = $(this).data('id')
            id = $.trim(id) //删除前后空格
            var remove = $('#remove').val()
            remove = $.trim(remove)
            var remove = ''!= remove?(remove.split(',')):[];
            if(-1==$.inArray(id,remove,0))
                remove.push(id)
            remove = remove.join(',')
            $('#remove').val(remove)

            $(this).closest('li').remove()
        })
        $('body').on('click', '.renyuan span.close', function () {
            $(this).parent('.ren').remove();
        })
//              选择业务人员
        $('#select').on('click', function () {
            var index = layer.getFrameIndex(window.name)
            //iframe层-父子操作
            layer.open({
                type: 2,
                title: '请选择业务人员',
                area: ['500px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("jxsgl/selectsalesman")}?frameindex=' + index
            });
            return false
        })
//        选择经销商
        $('body').on('click','.select2', function () {
            var id = $(this).closest('tr')[0].rowIndex
            //iframe层-父子操作
            layer.open({
                type: 2,
                title: '请选择经销商',
                area: ['500px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("selectJXS")}?id='+id
            });
            return false
        })

        /**
         * 测试(首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
         */
        $("#testNoBtn").bsSuggest({
            url: "{:url('provicejson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias: {userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            $(this).val('')
            var bool = false
            $('#renyuan .ren').each(function (idx, o) {
                if ($(this).data('id') == keyword.id) {
                    bool = true;
                }
            })
            if (bool == false)
                $('#renyuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<span class="close">×</span></span>')
            //console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        /**
         * 搜索自动补全所属经销商(首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
         */
        $(".testNoBtn2").bsSuggest({
            url: "{:url('jxsjson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias: {userName: "姓名"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            var testNoBtn = $(this).closest('td')
            testNoBtn.html('<span class="bqName" data-id="'+keyword.id+'">'+keyword.key+'<span class="delBqName">×</span></span><input type="hidden" name="jxs[id][]" value="'+keyword.id+'">')
            //ajax查询经销的编码、分区经理、省办经理、城市经理，并赋值给邮编的td
            $.post('{:url("findJxs")}',{id:keyword.id},function (data) {
                testNoBtn.next('td').html(data.sn)
                testNoBtn.next('td').next('td').html(data.zoning)
                testNoBtn.next('td').next('td').next('td').html(data.provice)
                testNoBtn.next('td').next('td').next('td').next('td').html(data.city)
            },'json')
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        //选择一级渠道类型
        $('#oneCType').on('change', function () {
            var id = $(this).val()
            $('#twoCType').load('{:url("twoCType")}?id=' + id)
        })

        //提交
        $('#tijiao').on('click',function () {
            var txt = $('.summernote').code();

            var form =  $('#add')
            var serial = form.serialize()
            serial = serial+'&brief='+txt

            var admin = []
            $('#renyuan .ren').each(function (idx,o) {
                admin.push($(o).data('id'))
            })
            var admin2 = ''
            if(admin)
                admin2 = admin.join(',')

            serial = serial+'&stuff='+admin2

            $.ajax({
                'type':'post',
                'url':'{:url("update",array("id"=>$data.id))}',
                'data':serial,
                'dataType':'json',
                'success':function (data) {
                    if(data.success){
                        swal({
                            title: data.msg,
                            type: "success"
                        },function(){
                            location.href = '{:url("index")}'
                        });

                    }else
                        swal({
                            title: data.msg,
                            type: "warning"
                        });
                }
            })
            return false
        })

        //删除联络信息-到回收站
        $('.delthis2').on('click',function () {
            var _this = this
            var id = $(this).data('id')
            if($(_this).text() == '删除'){
                $.ajax({
                        'type':'post',
                        'url':'{:url("delContact")}',
                        'data':{id:id},
                        'dataType':'json',
                        'success':function (data) {
                        if(data.success){
                            swal({
                                title: data.msg,
                                type: "success"
                            },function(){
                                $(_this).html('启用')
                            });

                        }else
                            swal({
                                title: data.msg,
                                type: "warning"
                            });
                        }
                })
            }else{
                $.ajax({
                        'type':'post',
                        'url':'{:url("enaContact")}',
                        'data':{id:id},
                        'dataType':'json',
                        'success':function (data) {
                        if(data.success){
                            swal({
                                title: data.msg,
                                type: "success"
                            },function(){
                                $(_this).html('删除')
                            });

                        }else
                            swal({
                                title: data.msg,
                                type: "warning"
                            });
                        }
                })
            }

            return false
        })

    })
</script>

<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>

<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });
    });
</script>
</body>

</html>